home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / pcw.zip / DEMO_D.C < prev    next >
C/C++ Source or Header  |  1991-12-28  |  3KB  |  61 lines

  1. /***********************************************************/
  2. /* File Id.                  Randwnd.C                     */
  3. /* Author.                   Stan Milam.                   */
  4. /* Date Written.             09 Sep 89                     */
  5. /*                                                         */
  6. /* Comments:  Generate random windows around the screen    */
  7. /* then move them around randomly until a key is pressed.  */
  8. /* Notice there is no code in this program to remove the   */
  9. /* windows:  We let the autoexit do it for us.             */
  10. /***********************************************************/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <conio.h>
  15. #include <time.h>
  16. #include <pcwproto.h>
  17.  
  18. #define MAXWND 20                      /* Max windows */
  19. #define random(m) (rand() % (m))       /* Random number generator macro */
  20. #define egacolor (_adaptor > CGA && _monitor == COLOR)
  21.  
  22. int demo_d(void) {
  23.  
  24.    WNDPTR *wnd[MAXWND];                /* Array of window */
  25.    int    fclr, bclr, r1, r2, c1, c2;  /* Colors & location */
  26.    int    mxr, mxc, lcv, ch;           /* Scratch Integers */
  27.    long   timer;                       /* For seeding random numbers */
  28.  
  29.    if ( mpresent ) hide_mouse();
  30.    fload(0,8);                          /* Load 8x8 font */
  31.    srand((int)time(&timer));            /* Seed random number generator */
  32.    chk_video_state(&mxr, &mxc);         /* Get max rows & cols */
  33.    for (lcv = 0; lcv < MAXWND; lcv++) { /* Put out MAXWND windows */
  34.      r1 = random(mxr-6)+1;r2 = r1 + 6;  /* Generate rows */
  35.      c1 = random(mxc-20)+1;c2 = c1 + 20;/* Generate columns */
  36.      do {                               /* Make sure the background */
  37.        fclr = random(15) + 1;           /*    and foreground are not equal */
  38.        bclr = random(7)  + 1;
  39.      } while (fclr == bclr);
  40.      bordercolor(fclr, bclr);           /* Set border color */
  41.      do {                               /* Make sure background color and */
  42.        fclr = random(16);               /*    and foreground != */
  43.        bclr = random(8);
  44.      } while (fclr == bclr);
  45.      wnd[lcv] = wframe(r1, c1, r2, c2, fclr, bclr);
  46.      wprintf(wnd[lcv], 3,CENTER,"Window %02d",lcv+1);
  47.    }
  48.    while ((ch = keypressed()) == 0) {   /* Do until key is pressed */
  49.        r1 = random(mxr - 6) + 1;        /* Randomly select row & column */
  50.        c1 = random(mxc - 20) + 1;
  51.        lcv= random(MAXWND);             /* Randomly select a window */
  52.        wndmove(wnd[lcv], r1, c1);       /* Move it */
  53.    }
  54.    if ( ch != 3 ) keyin();              /* If ch is not mouse read keyboard */
  55.    for (lcv = 0; lcv < MAXWND; lcv++)
  56.        wnd[lcv] = wpop( wnd[lcv] );
  57.    fload(0, (_adaptor == EGA) ? 14 : 16);
  58.    if ( mpresent ) show_mouse();
  59.    return(0);
  60. }
  61.